package 二叉树;

/**
 * TODO
 *
 * @Description
 * @Author Lx
 * @Date 2024/7/2 8:59
 **/
public class 二叉树的最近公共祖先 {

    //遍历二叉树
    static public void travelTree(TreeNode root){
        if(root==null)return;

        System.out.println(root.val);
        travelTree(root.left);
        travelTree(root.right);
    }


    public static void main(String[] args) {
        //1.建树
        TreeNode root = new TreeNode(1);
        root.left=new TreeNode(2);
        root.right=new TreeNode(3);
        TreeNode Node1=root.left;
        TreeNode Node2=root.right;


        Node1.left=new TreeNode(3);
        Node1.right=new TreeNode(4);


        Node2.left=new TreeNode(5);
        Node2.right=new TreeNode(6);

        TreeNode Node3=Node2.right;

        Node3.left=new TreeNode(7);

        //2.遍历
        travelTree(root);

    }
}
